﻿using OfficeOpenXml;
using ResilienceCompute.Tool;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
using LicenseContext = OfficeOpenXml.LicenseContext;

namespace ResilienceCompute
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();
            this.Load += MainForm_Load;
            this.FormClosing += MainForm_FormClosing;
        }

        private void MainForm_Load(object sender, EventArgs e)
        {
            SiemenPlc siemen = new SiemenPlc("192.168.110.10", "DB7300", 0);
            siemen.DataCallback += (value) =>
            {
                this.BeginInvoke(new Action(() =>
                {
                    lbl_resilienceA.Text = value.ToString();
                }));
            };
            siemen.Start();
            SiemenPlc siemenPlc = new SiemenPlc("192.168.110.10", "DB9300", 1);
            siemenPlc.DataCallback += (value) =>
            {
                this.BeginInvoke(new Action(() =>
                {
                    lbl_resilienceB.Text = value.ToString();
                }));
            };
            siemenPlc.Start();
        }

        private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            var result = MessageBox.Show("是否退出当程序？", "警告", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
            if (result != DialogResult.OK)
            {
                e.Cancel = true;
            }
        }
    }
}